package com.sskj.mine;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.App;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.mine.bean.PayWayBean;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.PaymentActivity;

import java.util.List;


/**
 * @author Hey
 * Create at  2019/05/01
 */
class PaymentPresenter extends BasePresenter<PaymentActivity> {

    public void requsetPayWayList() {
        OkGo.<HttpData<PayWayBean>>get(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_LIST)
                .execute(new JsonCallBack<HttpData<PayWayBean>>(this, false) {
                    @Override
                    public void onSuccess(Response<HttpData<PayWayBean>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            mView.updateUi(response.body().getData());
                        }
                    }
                });
    }

    // 支付方式开关
    public void payWayOpen(String type, int val) {
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL + HttpConfig.PAY_WAY_OPEN)
                .params("type", type)
                .params("val", val)  // 1开启 0关闭
                .execute(new JsonCallBack<HttpData<Object>>(this, false) {
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        if (response.body().getStatus() == HttpConfig.OK) {
                            requsetPayWayList();
                            ToastUtil.showShort(1 == val ? App.INSTANCE.getString(R.string.mine_paymentPresenter1) : App.INSTANCE.getString(R.string.mine_paymentPresenter2));
                        }
                    }

                    @Override
                    public void onError(Response<HttpData<Object>> response) {
                        super.onError(response);
                        requsetPayWayList();
                    }
                });
    }

}
